#include "xStringValueInterface.h"
#include "xLogManager.h"


namespace XE
{



	bool xStringValueInterface:: AddPropertyFun(const xString& name,GetPropertyFun getfun,SetPropertyFun setfun)
	{
		PropertyMapIterator it = m_FunMap.find(name);
		if(it!=m_FunMap.end())
		{
			xLogMessager::getSingleton().logMessage("xStringValueInterface add propertyFun Fail,has same name fun name is "+name);
			return false;
		}
		FunStrurct ss(setfun,getfun);
		m_FunMap.insert(std::make_pair(name,ss));
		return true;
	}

	bool xStringValueInterface::RemovePropertyFun(const xString& name)
	{

		PropertyMapIterator it = m_FunMap.find(name);
		if(it!=m_FunMap.end())
		{
			m_FunMap.erase(it);
			return true;
		}
		xLogMessager::getSingleton().logMessage("xStringValueInterface remove propertyFun Fail,can't fin the fun name is "+name);
		return false;
	}

	bool xStringValueInterface::FindPropertyFun(const xString & name,GetPropertyFun& getfun,SetPropertyFun& setfun)
	{
		PropertyMapIterator it = m_FunMap.find(name);
		if(it!=m_FunMap.end())
		{
			getfun  =it->second.m_GetFun;
			setfun  =it->second.m_SetFun;
			return true;
		}
		return false;
	}


	bool  xStringValueInterface::GetProperty(const xString& name,xString& value)	
	{
		SetPropertyFun setfun(NULL);
		GetPropertyFun getfun(NULL);

		if(FindPropertyFun(name,getfun,setfun))
		{
			 (this->*getfun)(value);
			 return true;
		}
		return false;

	}

	bool xStringValueInterface::SetProperty(const xString& name,const xString& value)
	{

		SetPropertyFun setfun(NULL);
		GetPropertyFun getfun(NULL);

		if(FindPropertyFun(name,getfun,setfun))
		{
			  (this->*setfun)(value);
			 return true;
		}
		return false;
	}




}